package com.text.textRecognition.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

/**
 * 全局配置类
 */
@Component
@Slf4j
public class InitConfig implements InitializingBean {

    private final AlipayConfig alipayConfig;

    public InitConfig(AlipayConfig alipayConfig) {
        this.alipayConfig = alipayConfig;
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("开始支付宝全局配置");

        Config config = new Config();
        config.protocol = alipayConfig.getProtocol();
        config.gatewayHost = alipayConfig.getGateway();
        config.signType = alipayConfig.getSingType();
        config.appId = alipayConfig.getAppId();
        config.merchantPrivateKey = alipayConfig.getPrivateKey();
        config.merchantCertPath = alipayConfig.getPublicKey();
//        config.alipayCertPath = alipayConfig.getAlipayCertPath();
//        config.alipayRootCertPath = alipayConfig.getAlipayRootCertPath();
        config.notifyUrl = alipayConfig.getNotifyUrl();
        Factory.setOptions(config);
        log.info("完成支付宝全局配置");
    }
}
